package com.yidu.hbatsft.service.impl;

import com.github.pagehelper.PageHelper;
import com.yidu.hbatsft.dao.AtsEmpAthleteMapper;
import com.yidu.hbatsft.dao.AtsEmpAthleteResultsMapper;
import com.yidu.hbatsft.domain.AtsEmpAthlete;
import com.yidu.hbatsft.domain.AtsEmpAthleteResults;
import com.yidu.hbatsft.service.AtsEmpResultsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class AtsEmpAtheleteResultsImpl implements AtsEmpResultsService {

    @Resource
    AtsEmpAthleteResultsMapper mapper;
    @Resource
    AtsEmpAthleteMapper athleteMapper;
    @Override
    public List<AtsEmpAthleteResults> findAll(String matchName,Integer pageNum,Integer pageSize) {
        //开始分页
        PageHelper.startPage(pageNum,pageSize);

        return mapper.findAll(matchName);
    }

    @Override
    public int cout() {
        return mapper.count();
    }

    @Override
    public int insertOrupDate(AtsEmpAthleteResults ats) {
        int cout =0;
        Integer athleteId = Integer.valueOf(ats.getAthleteName());//取到下拉框的值
        ats.setAthleteId(athleteId);
        AtsEmpAthlete athlete = athleteMapper.findByid(ats.getAthleteId());

        ats.setAthleteName(athlete.getAthleteName());
        if(ats.getResultId()==null){
            ats.setIsva(1);
            ats.setSort(1);
            cout = mapper.insert(ats);
        }else{
            cout = mapper.updateByPrimaryKeySelective(ats);
        }
        return cout;
    }

    @Override
    public int deleteByid(Integer id) {
        return mapper.deletematchDate(id);
    }

    @Override
    public AtsEmpAthleteResults findByid(Integer id) {
        return mapper.findById(id);
    }

    @Override
    public List<AtsEmpAthlete> loadingAthleteName() {
        return athleteMapper.findAllx();
    }
}
